<?php
/**
 * Fastapp.
 * 3/27/24
 * @Author deepsea
 * @Contact telegram:deepsea159
 */

namespace App\Fastapp\Api\Controller\Account;

use App\Fastapp\Api\Controller\ApiController;
use App\Fastapp\Api\Service\Account\FeedbackService;
use App\Fastapp\Aspect\ApiAuth;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\PostMapping;
use Psr\Http\Message\ResponseInterface;

#[Controller('api/feedback'), ApiAuth]
class FeedbackController extends ApiController
{
    #[Inject]
    public FeedbackService $service;

    #[GetMapping('list')]
    public function list(): ResponseInterface
    {
        return $this->success($this->service->list());
    }

    #[PostMapping('create')]
    public function create(): ResponseInterface
    {
        $data = $this->validate(self::RULE, [
            'content.*' => fastapp_t('account.v_12'),
        ]);
        return $this->service->create($data) ? $this->success() : $this->error();
    }

    const RULE = [
        'type' => 'required|integer',
        'content' => 'required',
        'images' => 'array',
    ];
}